/*
 Copyright (C) 2007 - Michael Opitz
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
#ifndef GMAIL_ACCOUNT_H
#define GMAIL_ACCOUNT_H

#include <glib.h>
#include <glib-object.h>
#include <malloc.h>
#include <string.h>

#include "my-ssl.h"
#include "base64.h"
#include "parser.h"

/*
 * Several Macros...
 */
G_BEGIN_DECLS 

#define GMAIL_ACCOUNT_TYPE		(gmail_account_get_type ())
#define GMAIL_ACCOUNT(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
					 GMAIL_ACCOUNT_TYPE, GmailAccount))
#define GMAIL_ACCOUNT_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), \
					 GMAIL_ACCOUNT_TYPE, GmailAccountClass))
#define GMAIL_IS_ACCOUNT(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
					 GMAIL_ACCOUNT_TYPE))
#define GMAIL_IS_ACCOUNT_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), \
					 GMAIL_ACCOUNT_TYPE))
#define GMAIL_ACCOUNT_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), \
					 GMAIL_ACCOUNT_TYPE, GmailAccountClass))
/** 
 * The mail, password and the MessageInfo structure can be set or get from the
 * GmailAccount.
 */
enum {
	GMAIL_ACCOUNT_MAIL = 1,
	GMAIL_ACCOUNT_PASSWORD,
	GMAIL_ACCOUNT_MESSAGES,
};

typedef struct _GmailAccountClass 	GmailAccountClass;
typedef struct _GmailAccount 		GmailAccount;
typedef struct _GmailAccountPriv	GmailAccountPriv;
typedef struct _MessageInfo 		MessageInfo;

/** 
 * This struct contains all the data for the GmailAccount class
 */
struct _GmailAccount {
	GObject parent;
	GmailAccountPriv *priv;
};

/** 
 * This struct represents a GmailAccount class.
 */
struct _GmailAccountClass {
	GObjectClass parent_class;

	/* class members */
	GList* (*login) (GmailAccount *self);
};

struct _MessageInfo {
	/** 
	 * the email address from the original sender of the message.
	 */
	char *from_mail;
	/** 
	 * The name of the original sender of the message.
	 */
	char *from_name;
	/** 
	 * The subject of the email message.
	 */
	char *subject;
	/** 
	 * A small summary of the email message.
	 */
	char *snipped;
	/** 
	 * The url to google for the email message.
	 */
	char *url;
};

/* the usual GObject initialization and cleanup functions */
GType 
gmail_account_get_type ();
GType
gmail_account_register_type (GTypeModule *module);

GObject *
gmail_account_constructor (GType type, 
			   guint n_construct_properties,
			   GObjectConstructParam *construct_properties);

void 
gmail_account_instance_finalize (GObject *obj);
void 
gmail_account_instance_init (GTypeInstance *instance, gpointer g_class);

void 
gmail_account_class_init (gpointer g_class, gpointer class_data);

void 
gmail_account_instance_dispose (GObject *object);

void
gmail_account_get_property (GObject 	*object,
			    guint	 property_id,
			    GValue	*value,
			    GParamSpec	*pspec);
void 
gmail_account_set_property (GObject 	*object,
			    guint 	property_id,
			    const GValue *value,
			    GParamSpec 	*spec);


/** 
 * gmail_account_login:
 * 
 * @account: a pointer to a GmailAccount
 *
 * This function logs the account into Gmail and returns a List of MessageInfo's
 * 
 * Returns: A list of MessageInfo's
 */
GList* 
gmail_account_login (GmailAccount *account);

/** 
 * gmail_account_load:
 *
 * This function loads all GmailAccounts from a file.
 * 
 * Returns: A GList which consists of GmailAccount
 */
GList* 
gmail_account_load ();

/** 
 * gmail_account_save:
 *
 * This function stores all GmailAccounts into a file.
 * 
 * @accounts: is a list of GmailAccounts.
 */
void
gmail_account_save(GList *accounts);

G_END_DECLS

#endif
